<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/6
 * Time: 14:10
 */

namespace app\api\controller;

require EXTEND_PATH.'phpoffice/src/phpword/Shared/ZipArchive.php';
require EXTEND_PATH.'phpoffice/src/phpword/TemplateProcessor.php';
require EXTEND_PATH.'phpoffice/src/phpword/Settings.php';
use app\admin\model\BydAbout;
use app\admin\model\BydBusiness;
use app\admin\model\BydColor;

use app\admin\model\BydDesfollow;
use app\admin\model\BydDistri;
use app\admin\model\BydPricture;
use app\common\controller\News;
use think\Db;
use app\admin\model\BydDesigner;
use app\admin\model\BydDesignerMake;
use app\admin\model\BydDesignerPro;
use app\admin\model\BydDestri;
use app\admin\model\BydDispro;
use app\admin\model\BydHome;
use app\admin\model\BydHuxin;
use app\admin\model\BydIndexcontent;
use app\admin\model\BydPage;
use app\admin\model\BydQjset;
use app\admin\model\BydRecruit;
use app\admin\model\BydSetleft;
use app\admin\model\BydSetxq;
use app\admin\model\BydStyle;
use app\admin\model\BydVideo;
use app\admin\model\BydZan;
use app\api\model\BydSet;
use app\common\controller\Api;
use PhpOffice\PhpWord\TemplateProcessor;

header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
class Bydindex extends Api
{
    /**
     * 无需登录的方法,同时也就不需要鉴权了
     * @var array
     */
    protected $noNeedLogin = ['*'];

    /**
     * 首页-栏目
     */
    public function indexbar()
    {
        $arr = BydHome::select();
        foreach ($arr as &$v) {
            $v['url'] = BydPage::where('id', $v['page'])->find();
        }
        $open=BydBusiness::where('id',2)->find();
        if($open['switch']==1){
            $edit=true;
        }else{
            $edit=false;
        }
        $sx=3;//刷新多少次清除缓存
        $edits=true;//限时抢购
        $kehu=true;//客服图标
        $ids=[8,120,74,113,5,75,62,54];
        $this->success(__('请求成功'), ['status' => $arr,'edit'=>$edit,'edits'=>$edits,'kefu'=>$kehu,'sx'=>$sx]);
    }

    /**
     * 首页-旗舰导航
     * @param integer $setid` '套系的id',
     * @param integer $limit` '分页的数量',
     * setid 套系分类id（全部时传0）
     */
    public function qjset()
    {
        $data = $this->request->request('');
        $arr = BydSet::indexset($data);
        if($arr){
            $this->success(__('请求成功'), ['status' => $arr]);
        }else{
            $this->error('请求失败');
        }
    }

    /**
     * 套系详情左侧导航栏
     * @param integer $setleft_id` '套系左侧的id',
     */
    public function setleft()
    {
        $data = $this->request->request('');
        if(empty($data['setleft_id']))     $this->error('参数不能为空');
        $find=BydSet::find($data['setleft_id']);
        if(empty($find))$this->error('数据不存在');
        $arr = BydSetleft::where('id','in',$find['leftid'])->order('id asc')->select();
        //$arr = BydSetleft::order('id asc')->select();
        if($arr){
            $this->success(__('请求成功'), ['status' => $arr]);
        }else{
            $this->error('请求失败');
        }
    }

    /**
     * 旗舰套系详情
     * @param integer $id` '套系id',
     * id 套系id
     */
    public function setxq()
    {
        $data = $this->request->request('');
        $find = db('BydSet')->where('id',$data['id'])->find();
        //print_r($find);die;
        $set=db('BydSet')->where('id',$data['id'])->find();
        $image=explode(",", $set['image']);
        foreach ($image as &$v){
            $ii=BydPricture::where('image',$v)->find();
            $im[]=$ii;
        }
        $arrs = explode(",", $set['leftid']);
        foreach ($arrs as &$v){
            $qq=BydSetleft::where('id',$v)->find();
            $aa[]=$qq;
        }

        $arr = db('BydSetxq')->where('setid', $data['id'])->order('leftid asc')->select();
        if ($arr) {
            foreach ($arr as &$v) {
                //$v['left'] = BydSetleft::find($v['leftid']);
                //$v['des']=BydDesigner::find()
                $pic=BydPricture::where('image','in',$v['imageid'])->select();
                if(!empty($pic)){
                    foreach ($pic as $value){
                        $v['shop']=\app\api\model\BydShop::find($value['shopid']);
                        $v['shop']['photo']=$value['image'];
                    }
                }
//                    if(empty($shop)){
//                        $v['shop']=[];
//                    }else{
//                        $v['shop']=$shop;
//                    }
            }
        }
        $find['imagexq']=$im;
        $find['xq'] = $arr;
        if ($find) {
           $find['deslg']= preg_replace("/\/uploads\//",'https://bao.scwushen.com/uploads/', $find['deslg'] );
//var_dump($find);die;
            $this->success(__('请求成功'), ['status' => $find,'left'=>$aa]);
        } else {
            $this->error('暂无数据');
        }
    }
    /**
     * 首页瀑布流
     */
    public function indexcontent(){
        $arr = BydIndexcontent::where('switch',1)->order('weigh desc')->select();
        if ($arr) {
            $this->success(__('请求成功'), ['status' => $arr]);
        } else {
            $this->error('暂无数据');
        }
    }
    /**
     * 首页搜索
     * @param integer $name 查询内容
     */
    public function indexlike()
    {
        $data = $this->request->request('');
        $map['name'] = ['like', '%' . $data['name'] . '%'];
        $arr = BydIndexcontent::where($map)->select();
        if ($arr) {
            $this->success(__('请求成功'), ['status' => $arr]);
        } else {
            $this->error('暂无数据');
        }
    }

    /**
     * 首页-旗舰套系分类
     */
    public function setcategory()
    {
        $arr = BydQjset::order('sort desc')->select();
        if ($arr) {
            $this->success(__('请求成功'), ['status' => $arr]);
        } else {
            $this->error('请求失败');
        }
    }

    /**
     * 首页轮播图
     */
    public function banner()
    {

        $arr = BydSet::banner();


        if (!empty($arr)) {
            $this->success(__('请求成功'), ['status' => $arr]);
        } else {
            $this->error('暂无数据');
        }
    }

    /**
     * 户型攻略
     * @param integer $id` '分类id',
     * id 分类id
     */
    public function huxin()
    {
        $data = $this->request->request('');
        $arr = BydSet::huxin($data);
        if ($arr == null) {
            $this->error('暂无数据');
        } else {
            $this->success(__('请求成功'), ['status' => $arr]);
        }
    }

    /**
     * 户型攻略分类
     * @param integer $user_id` '用户id',
     * user_id 用户id
     */
    public function huxincategory()
    {
        $arr = BydSet::huxincategory();
        if ($arr == null) {
            $this->error('暂无数据');
        } else {
            $this->success(__('请求成功'), ['status' => $arr]);
        }
    }

    /**
     * 佳作分享
     * @param integer $user_id` '用户id',
     */
    public function enjoy()
    {
        $data = $this->request->request('');
        //if(empty($data['state']))$this->error('缺少参数');
        $arr = BydSet::goodpr($data);
        //$arr=BydVideo::where('id',41)->find();
        $this->success(__('请求成功'), ['status' => $arr]);
        if ($arr == null) {
            $this->error('暂无数据');
        } else {
            $this->success(__('请求成功'), ['status' => $arr]);
        }
    }
    /**
     * 视频得评论
     * @param integer $id` '视频id',
     */
    public function videopl(){
        $data = $this->request->request('');
        if(empty($data['id']))$this->error('参数错误');
        $wheres['video_id'] = $data['id'];
        $pl = db('BydPl')->where($wheres)->order('id desc')->select();//查询出这个帖子的所有评论

        if (!empty($pl)) {
            //循环每一条评论
            foreach ($pl as $key => &$vv) {
                $wheree['id'] = $vv['user_id'];
                $usfind = db('BydUser')->where($wheree)->field('username,avatar')->find();//找到此条评论的用户新西
                $vv['name'] = $usfind['username'];
                $vv['head'] = $usfind['avatar'];
                if (!@fopen($vv['head'], 'r')) {
                    $vv['head'] = 'http://bao.scwushen.com' . $vv['head'];//头像
                }
                $wh['pl_id'] = $vv['id'];
                // $wh['pl_user_id'] = $v['user_id'];
                $vv['list'] = db('BydPlhf')->where($wh)->order('create_at desc')->select();//找到此条评论的回复
                if ($vv['list']) {
//                            $asa=$v['tt'];
                    foreach ($vv['list'] as &$q) {
                        $q['bhhfuser'] = db('BydUser')->where('id', $q['pl_user_id'])->field('username,avatar')->find();//找到被回复人的信息
                        $qqq = db('BydUser')->where('id', $q['user_id'])->field('username,avatar')->find();//找到回复人的信息
                        $q['user'] = $qqq;
                    }
                }
            }
            $this->success(__('请求成功'), ['status' => $pl]);         //print_r($v);die;
        }else{
            $this->error('暂无数据');
        }
    }
    /**
     * 点赞与取消点赞
     *  @param integer $type` '为点赞1为取消点赞',
     *  @param integer $user_id` '用户id',
     * @param integer $video_id` '视频id',
     *   @param integer $state` '为视频1为设计师',
     *
     * type 0为点赞1为取消点赞
     * user_id  用户id
     * video_id  视频id
     *state 0为视频1为设计师
     */
    public function zan()
    {

        $data = $this->request->request('');
        $cnt = 0;
        
        $add=new BydZan();
        #检查是否有点赞
        #无则添加
        #有则删除
        #删除后减少对应记录赞数
        $where =  [
                'video_id'  => $data['video_id'],
                'user_id'  => $data['user_id'],
                'state'  => $data['state'],
            ];
        $status = 0;
//        $where['video_id']=$data['video_id'];
//        $where['user_id']=$data['user_id'];
//        $where['state']=$data['state'];
        $zaned = BydZan::where($where)->find();

        if(empty($zaned))
        {
            #添加
             $add->data([
                'video_id'  => $data['video_id'],
                'user_id'  => $data['user_id'],
                'state'  => $data['state'],
            ]);
            $res = $add->save();
            if($res){
                if($data['state'] ==0){
                    $sum=BydVideo::where('id',$data['video_id'])->setInc('zan',1);
                }else{
                    $sum=BydDesigner::where('id',$data['video_id'])->setInc('zan',1);
                }

                $status = 1;
            }
        }
        else
        {

            #更新
            $del=BydZan::where('id',$zaned['id'])->delete();
            //$del=$add->where('video_id',$data['video_id'])->where('user_id',$data['user_id'])->delete();
            if($del){
                if($data['state']==1){
                    $find=BydDesigner::where('id',$data['video_id'])->find();
                    if($find['zan']>0){
                        $dec=BydDesigner::where('id',$data['video_id'])->setDec('zan',1);
                        $status = 1;
                    }
                }else{
                    $find=BydVideo::where('id',$data['video_id'])->find();
                    if($find['zan']>0){
                        $dec=BydVideo::where('id',$data['video_id'])->setDec('zan',1);
                        $status = 1;
                    }
                }


            }
        }
        
            
        if($status) 
        {
            $cnt = 0;
                if($data['state'] ==0){
                    $cnt=BydVideo::where('id',$data['video_id'])->field('zan')->find();
                }else{
                    $cnt=BydDesigner::where('id',$data['video_id'])->field('zan')->find();
                }
            $this->success(__('请求成功'), ['zan' => $cnt['zan']]);
        }
        else $this->error('请求失败');


//        $arr = BydSet::videozan($data);
//        if ($arr==null) {
//            $this->error('请求失败');
//        } else {
//            $this->success(__('请求成功'));
//        }
    }

    /**
     * 佳作分享风格分类
     */
    public function style()
    {
        $arr = BydStyle::select();
        if ($arr) {
            $this->success(__('请求成功'), ['status' => $arr]);
        } else {
            $this->error('暂无数据');
        }
    }

    /**
     * 色调分类
     */
    public function color()
    {
        $arr = BydColor::select();
        if ($arr) {
            $this->success(__('请求成功'), ['status' => $arr]);
        } else {
            $this->error('暂无数据');
        }
    }

    /**
     * 商品评价
     * @ApiMethod (POST)
     * @param integer $id 视频的id
     * @param integer $userid 用户的id
     * @param varchar $content 评价的内容
     * @param varchar $image 评价的内容
     * @param varchar $state 0为设计师1为视频
     */
    public function pl()
    {
        $data = $this->request->request('');
        $creat = \app\api\model\BydSet::pl($data);
        if ($creat == null) {
            $this->error('请求失败');
        } else {
            $this->success(__('请求成功'));
        }
    }

    /**
     *   回复评论
     * @ApiMethod (POST)
     * @param integer $pl_id 评论的id
     * @param integer $pl_user_id 被回复人的id
     * @param integer $userid 用户的id
     * @param varchar $content 评价的内容
     */
    public function plhf()
    {
        $data = $this->request->request('');
        $hf = \app\api\model\BydSet::hfpl($data);
        if ($hf==null) {
            $this->error('请求失败');
        } elseif ($hf == false) {
            $this->error('暂无回复资格');
        } else {
            $this->success(__('请求成功'));
        }
    }

    /**
     * 楼盘设计筛选条件
     */
    public function loupancategory()
    {
        $arr = BydSet::loupancategory();
        if ($arr == null) {
            $this->error('暂无数据');
        } else {
            $this->success(__('请求成功'), ['status' => $arr]);
        }
    }

    /**
     * 楼盘设计列表
     * @param integer $limit` '分页数量',
     */
    public function loupanden()
    {
        $data = $this->request->request('');
        $arr = BydDesignerPro::order('id desc')->paginate($data['limit']);
        if ($arr) {
            $this->success(__('请求成功'), ['status' => $arr]);
        } else {
            $this->error('暂无数据');
        }
    }

    /**
     * 楼盘设计详情
     * @param integer $id 作品id
     */
    public function loupanxq()
    {
        $data = $this->request->request('');
        $lp=new BydSet();
        //$arr = $lp->loupanxq($data);
        $find=db('BydDesignerPro')->where('id',$data['id'])->find();
        if ( empty($find)) $this->error('暂无数据');
        $find['des']=BydDesigner::find($find['des_id']);//设计师
        $find['des']['zans']=BydZan::where('user_id',$data['user_id'])->where('video_id',$find['des_id'])->where('state',1)->find();
        $follows=BydDesfollow::where('text_id',$find['des_id'])->where('user_id',$data['user_id'])->find();
        if($follows){
            $find['des']['follows']=0;
        }else{
            $find['des']['follows']=1;
        }
        if ($find) {
            $this->success(__('请求成功'), ['status' => $find]);

        } else {
            $this->error('暂无数据');
            //$this->success(__('请求成功'), ['status' => $arr]);
        }
    }

    /**
     * 楼盘设计搜索
     * @param integer $name 查询内容
     */
    public function loupanlike()
    {
        $data = $this->request->request('');
        $map['name'] = ['like', '%' . $data['name'] . '%'];
        //$map['state'] = ['eq', 1];
        $arr = BydDesignerPro::where($map)->select();
        if($arr){
            $this->success(__('请求成功'), ['status' => $arr]);
        } else {
            $this->error('暂无数据');
        }
    }

    /**
     * 关于宝云邸
     * @param integer $state 0=品牌故事1为业务地图2为创始人3为方黄集团
     */
    public function bydadout()
    {
        $data = $this->request->request('');
        $arr = BydAbout::where('state', $data['state'])->select();
        if ($arr) {
            $this->success(__('请求成功'), ['status' => $arr]);
        } else {
            $this->error('暂无数据');
        }
    }

    public function qq()
    {
//        $com = new COM('word.application');  （#注意word.application 是电脑中必须有word文档才可以的）
//echo $com;
//        $path = storage_path('aa.docx');
//        $file_path=Storage::path();
//        // 生成world 存放目录
//        $filePath = storage_path('contract.docx');
        // 声明模板象并读取模板内容
//        $templateProcessor = new TemplateProcessor("./qq.docx");
//        // 替换模板内容
//        $templateProcessor->setValue('name', '北京乙方');  // 乙方
//
//        // 生成新的 world
//       $templateProcessor->saveAs($filePath);

        $templateProcessor = new TemplateProcessor("./qq.docx");
        $templateProcessor->setValue('name', '周起');

        $templateProcessor->saveAs("./b.docx");

    }

    public function word2pdf()
    {
       // $com = new \COM('word.application');  （#注意word.application 是电脑中必须有word文档才可以的）

        $templet['id'] = 4;
        $server = $_SERVER['DOCUMENT_ROOT'];
        $filenamedoc = $server . '/uploads/cs.docx';
        //echo $filenamedoc;die;
        //$filenamedoc =$server.'/'.$templet['url'];//模板路径
        $filenamepdf = $server . '/uploads/one' . $templet['id'] . '_new.docx';//替换变量，新的word路径
        $fiel = '/uploads/one' . $templet['id'] . '_new' . time() . '.pdf';//word转换pdf路径
        $pdf = $server . $fiel;
        $tmp = new \PhpOffice\PhpWord\TemplateProcessor($filenamedoc);//打开模板
        $tmp->setValue('name', '杨昊');
        $tmp->setValue('sf', '514598744458262201');
        $tmp->setValue('address', '四川省成都市青羊区金沙遗址');
        $tmp->setValue('phone', '17685489542');
        $tmp->setValue('email', '894184831@qq.com');

        $tmp->saveAs($filenamepdf);//另存为
        $url = $this->word2pdf($filenamepdf, $pdf);
        return 111;
    }

    function word2pdfs($srcfilename, $destfilename)
    {
        try {
            if (!file_exists($srcfilename)) {
                unlink($srcfilename);
            }
            $word = new \COM("word.application") or die("Can't start Word!");
            $word->Visible = 0;
            $word->Documents->Open($srcfilename, false, false, false, "1", "1", true);
            $word->ActiveDocument->final = false;
            $word->ActiveDocument->Saved = true;
            $word->ActiveDocument->ExportAsFixedFormat(
                $destfilename,
                17,                         // wdExportFormatPDF
                false,                      // open file after export
                0,                          // wdExportOptimizeForPrint
                3,                          // wdExportFromTo
                1,                          // begin page
                5000,                       // end page
                7,                          // wdExportDocumentWithMarkup
                true,                       // IncludeDocProps
                true,                       // KeepIRM
                1                           // WdExportCreateBookmarks
            );
            $word->ActiveDocument->Close();
            $word->Quit();
        } catch (\Exception $e) {
            if (method_exists($word, "Quit")) {
                $word->Quit();
            }
            return  111;
        }
    }
    /**
     * 生成二维码
     *  @param  string  $id  用户id
     *   @param  string $level 身份
     */
    public function ewm(){
        $data = $this->request->request('');
        $shop=new \app\api\model\BydShop();
        $arr=$shop->ewm($data);
        if($arr==null){
            $this->error('请求失败');
        }else {
            $this->success(__('请求成功'), ['status' => $arr]);
        }
    }
    public function qwer(){
        $pro=[
            'pid'=>17,
            'family'=>6,
            'level'=>0,
        ];
        $order=[
            'price'=>1,
            'user_id'=>8,
        ];
        $data=[
            'out_trade_no'=>'123546789'
        ];
        $father=\app\admin\model\BydUser::where('id',$pro['pid'])->find();//查看父级身份
        if($father['bbs']>0){
            $level=\app\admin\model\BydIdentity::find($father['bbs']);
            $ftc=$order['price']*$level['myproduct']/100;//上级所得提成
        }
        $ftc=$order['price']*$level['myproduct']/100;//上级所得提成
        $gfather=\app\admin\model\BydUser::where('id',$pro['family'])->find();//查看第一级别身份
        $levels=\app\admin\model\BydIdentity::find($gfather['bbs']);
        if($gfather['bbs']>0 && $father['bbs']==0){
            $gtc=$order['price']*$levels['sonproduct']/100;//上级所得提成
            $add = new BydDispro();

            $add->data([
                'cjprice'=>$order['price'],
                'level'=>$pro['level'],
                'pid'  => $pro['family'],
                'money'=>1,
                'state' =>  1,
                'user_id' =>  $order['user_id'],
                'type' => 0,
                'tixian' => 0,
                'order_id'=>$data['out_trade_no'],
                'price'=>$gtc
            ]);

            $add->save();

        }
    }
    public function qwerr(){
        $data=[
          'out_trade_no'=>'D2022010412845'
        ];
        $desdmake=BydDesignerMake::where('dorderid',$data['out_trade_no'])->find();//设计师预约设计定金
        $deswmake=BydDesignerMake::where('worderid',$data['out_trade_no'])->find();
        $make=new BydDesignerMake();
        if($desdmake){
            $save=$make->where('dorderid',$data['out_trade_no'])->update(['states'=>1]);
            if($save){
                return 1111;
            }else{
                return  2222;
            }
        }

    }
    public function timego(){
        $time=time();
        $timedate=datetime(time(),'Y年m月d日');

        $a=strtotime("+12 month",time());
        $timedates=datetime($a,'Y年m月d日');

    }
    /**
     * 招募令
     */
    public function recruit(){
        $arr=BydRecruit::select();
        if (empty($arr))  $this->error('暂无数据');
        foreach ($arr as &$v){
            $v['content']=preg_replace("/\/uploads\//",'https://bao.scwushen.com/uploads/', $v['content'] );
        }
        $this->success(__('请求成功'), ['status' => $arr]);
    }
/**
 *
 */
    public function qaq(){
        $data=[
            'pid'=>'8',
            'level'=>'0'
        ];
        $find=[
            'id'=>60,
        ];
        if ($data['pid']>0 && $data['level']>0){
            if($data['level']<3){
                $bbs=BydDistri::where('user_id',$data['pid'])->find();//查看拉新人的身份
                $disfind=BydDistri::where('user_id',$find['id'])->find();//查看是否有上级

                if(!empty($bbs)){
                    if($bbs['family']>0){
                        //bs拉新
                        $add = new BydDistri();
                        $add->data([
                            'family'  => $bbs['family'],
                            'pid' =>  $data['pid'],
                            'user_id' =>  $find['id'],
                            'level' =>  $data['level']
                        ]);
                        $add->save();
                    }else{
                        //b1
                        $add = new BydDistri();
                        $add->data([
                            'family'  => $data['pid'],
                            'pid' =>  $data['pid'],
                            'user_id' =>  $find['id'],
                            'level' =>  $data['level']
                        ]);
                        $add->save();
                    }
                }
            }else{
                $des=BydDestri::where('user_id',$data['pid'])->find();//查看拉新人的身份
                if(!empty($des)){
                    if($des['family']>0){
                        //d1拉新
                        $add = new BydDestri();
                        $add->data([
                            'family'  => $des['family'],
                            'pid' =>  $data['pid'],
                            'user_id' =>  $find['id'],
                            'level' =>  $data['level']
                        ]);
                        $add->save();
                    }else{
                        //d2
                        $add = new BydDestri();
                        $add->data([
                            'family'  => $data['pid'],
                            'pid' =>  $data['pid'],
                            'user_id' =>  $find['id'],
                            'level' =>  $data['level']
                        ]);
                        $add->save();
                    }
                }
            }
        }else{
            if($data['pid']>0){
                $puser=\app\admin\model\BydUser::find($data['pid']);
                if(!empty($puser)){
                    $piddis=BydDistri::where('user_id',$data['pid'])->find();
                    if($piddis){
                        //查看pid身份
                        $shenfen=\app\admin\model\BydUser::find($piddis['pid']);
                        //$shenfenfamily=\app\admin\model\BydUser::find($piddis['pid']);
                        if($shenfen){
//                            print_r($piddis['pid']);die;
                            if($shenfen['bbs']==0){
//                                echo 111;die;
                                $add = new BydDistri();
                                $add->data([
                                    'family'  => $piddis['family'],
                                    'pid' =>  $data['pid'],
                                    'user_id' =>  $find['id'],
                                    'level' =>  $data['level']
                                ]);
                                $add->save();
                            }else{
                                $add = new BydDistri();
                                $add->data([
                                    'family'  => $piddis['pid'],
                                    'pid' =>  $data['pid'],
                                    'user_id' =>  $find['id'],
                                    'level' =>  $data['level']
                                ]);
                                $add->save();
                            }
                        }
                    }
                    else{
                        //c拉c
                        if($puser['bbs']==0){
                            $add = new BydDistri();
                            $add->data([
                                'family'  => 0,
                                'pid' => 0,
                                'user_id' =>  $data['pid'],
                                'level' => 0
                            ]);
                            $add->save();
                            $add = new BydDistri();
                            $add->data([
                                'family'  => $data['pid'],
                                'pid' => $data['pid'],
                                'user_id' => $find['id'],
                                'level' => 0
                            ]);
                            $add->save();
                        }
                    }
                }
            }
        }
    }
    public function ces(){

        $user=\app\admin\model\BydUser::find(47);
        $arr=[
            'openid'=>$user['openid'],
            'thing1'=>"申请成为设计师",
            'thing2'=>"通过审核",
            'time'=>date('Y年m月d日 H:i',time()),
            'thing5'=>"12312",
        ];
        $new=new News();
        $news=$new->desnews($arr);
    print_r($news);
    }
    public function sendmessage(){
        $data=$_POST=json_decode(file_get_contents('php://input'), TRUE);
        $access_token=$this->getAccessToken();
        $request_url='https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='.$access_token;
        $request_data=array(
            'touser'=>$data['touser'],//接收者（用户）的 openid
            'template_id'=>$data['template_id'],//所需下发的模板消息的id
            'page'=>$data['page'],//点击模板卡片后的跳转页面
            'form_id'=>$data['form_id'],//表单提交场景下，为 submit 事件带上的 formId；支付场景下，为本次支付的 prepay_id
            'data'=>$data['data'],//"keyword1": {"value": "339208499", "color": "#173177"}
            'emphasis_keyword'=>$data['emphasis_keyword']//模板需要放大的关键词，不填则默认无放大
        );
        $return=json_decode($this->Http($request_url,$request_data,'json'),true);
        $this->response($return,'json');
    }
   /**
    * http
    */
  public function cece(){
      $source = "45_0,25_1,55_2,25_3";//按逗号分离字符串
      $hello = explode(',',$source);
      foreach ($hello as $v){
          $qq = explode('_',$v);
          if($qq[1]==0){
              $sex='先生';
          }elseif($qq[1]==1){
              $sex='女士';
          }elseif($qq[1]==2){
              $sex='男孩';
          }elseif($qq[1]==3){
              $sex='女孩';
          }
          $arr="$sex-$qq[0]岁";
          $qwe[]=$arr;

      }
      $comma_separated = implode(",", $qwe);
  }
  /**
   * ceshi
   */
public function urlce(){
    $new=new News();
    $qq=$new->xcxurl(142,0);
    print_r($qq);
}
}